// Filename: views/person/savePerson
define([
  'jquery',
  'underscore',
  'backbone',  
  // Pull in the Model from above
  'models/user',
  'text!../../../templates/modifyPersonTemplate.html'  
], function($, _, Backbone, UserModel, modifyPersonTemplate){
	var PersonSaveView = Backbone.View.extend({
			el: '.page',
			render: function() {
				var that = this;
				var template = _.template(modifyPersonTemplate, {user:null});
					that.$el.html(template);
			},
			events: {
				'submit .edit-user-form' : 'saveUser'				
			},
			saveUser: function (ev) {
				var userDetails = $(ev.currentTarget).serializeObject();
				var user = new UserModel();
				user.save(userDetails, {
					success: function(user){
						Backbone.history.navigate('', {trigger: true});
					}, 
					error: function(user, response){
						console.log(response.status);
					}
				});
				//console.log(userDetails);
				return false;
			}
		});
  // Returning instantiated views can be quite useful for having "state"
  return PersonSaveView;
});